package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IOrderDetailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.OrderDetailReqVO;
import com.bjc.base.bean.response.OrderDetailVO;

/**
 * <p>
 * 订单详情 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "orderDetail-api", tags = { "订单详情相关接口" })
public class OrderDetailController {

    @Autowired
    private IOrderDetailService orderDetailService;

	@ApiOperation("分页查询订单详情")
	@GetMapping("orderDetail/findPage")
	public ResultVO getOrderDetailPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			OrderDetailReqVO orderDetailReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<OrderDetailVO> orderDetailVOs = orderDetailService.getList(orderDetailReqVO);
		return ResultGenerator.getSuccess(new PageInfo<OrderDetailVO>(orderDetailVOs));
	}
	
	@ApiOperation("分页查询订单详情")
	@GetMapping("orderDetail/find")
	public ResultVO getOrderDetaile(OrderDetailReqVO orderDetailReqVO) {
		OrderDetailVO orderDetailVO = orderDetailService.get(orderDetailReqVO);
		return ResultGenerator.getSuccess(orderDetailVO);
	}

	@ApiOperation("添加订单详情")
	@PostMapping("orderDetail/create")
	public ResultVO createOrderDetail(@RequestBody OrderDetailReqVO orderDetailReqVOs) {
		int count = orderDetailService.insert(orderDetailReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新订单详情")
	@PutMapping("orderDetail/update")
	public ResultVO updateOrderDetail(@RequestBody OrderDetailReqVO orderDetailReqVOs) {
		int count = orderDetailService.update(orderDetailReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除订单详情")
	@DeleteMapping("orderDetail/deleteList")
	public ResultVO deleteOrderDetail(@ApiParam(value = "orderDetail id集合") @RequestBody int[] ids) {
		int count = orderDetailService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
